<?php

namespace App\Http\Requests\Mini\Shop;

use Illuminate\Foundation\Http\FormRequest;

class Refund extends FormRequest
{
    public $action;

    public function __construct()
    {
        parent::__construct();
        $this->action = request()->route()->getName();
    }


    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * 2021/3/11--20:49
     * @return array
     * @author:董宗澳
     * @email:2453611300
     * @wechat:DZA74941
     * @QQ:2453611300
     * @web:www.quzha.net
     * @method:rules
     * @effect:验证规则
     */
    public function rules()
    {
        $rules = [];
        switch ($this->action) {
            // 添加售后路由
            case 'addRefund':
                $rules = [
                    'order_id' => 'required',
                    'refund_type' => 'required',
                ];
                break;
            case 'refund_before':
                $rules = [
                    'order_id' => 'required'
                ];
                break;
            case 'showRefund':
                $rules = [
                    'order_id' => 'required'
                ];
                break;
            case 'update':
                $rules = [
                    'order_id' => 'required',
                    'delivery_no' => 'required',
                    'delivery_code' => 'required',
                    'user_phone' => 'required'
                ];
                break;
        }

        return $rules;
    }

    /**
     * 2021/3/11--20:50
     * @return array|void
     * @author:董宗澳
     * @email:2453611300
     * @wechat:DZA74941
     * @QQ:2453611300
     * @web:www.quzha.net
     * @method:messages
     * @effect:路由验证消息
     */
    public function messages()
    {
        $message = [];
        switch ($this->action) {
            case 'addRefund':
                $message = [
                    'order_id.required' => '请传递订单id',
                    'refund_type' => '请传递售后类型'
                ];
                break;
            case 'refund_before':
                $message = [
                    'order_id.required' => '请传递订单id',
                ];
                break;
            case 'showRefund':
                $message = [
                    'order_id.required' => '请传递订单id',
                ];
                break;

            case 'update':
                $message = [
                    'order_id.required' => '请传递订单id',
                    'delivery_no.required' => '请传递快递单号',
                    'delivery_code.required' => '请传递快递编码',
                    'user_phone.required' => '请传递手机号',
                ];
                break;
        }
        return $message;
    }
}
